/******************************************************************************
 * Copyright (C) 2025 COMPANY or its affiliates.
 *
 * All Rights Reserved.
 *
 @file bsp_flash.h
 *
 @par dependencies
 - ${stdint.h}          // 标准类型定义
 - ${other_common.h}    // 公共宏定义
 *
 @author liubin | R&D Dept. | COMPANY
 *
 @brief 模块对外接口声明，包括：
            - 数据结构定义（如xxx结构体）
            - 枚举类型定义（如xxx状态枚举）
            - 函数接口声明（如xxx_init/xxx_process）
 *
 @version V1.0 2025-11-09
 *
 @note 1 tab == 4 spaces!
 *       - 使用说明：如接口调用顺序、参数范围限制
 *       - 移植说明：如跨平台需适配的宏、条件编译
 *       - 兼容性：与旧版本接口的兼容说明
 *
 *****************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/

#ifndef BSP_FLASH_H
#define BSP_FLASH_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
/* Exported types ------------------------------------------------------------*/
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000)  // 扇区0起始地址, 16 Kbytes
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000)  // 扇区1起始地址, 16 Kbytes
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000)  // 扇区2起始地址, 16 Kbytes
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000)  // 扇区3起始地址, 16 Kbytes
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000)  // 扇区4起始地址, 64 Kbytes
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000)  // 扇区5起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000)  // 扇区6起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000)  // 扇区7起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000)  // 扇区8起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000)  // 扇区9起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) // 扇区10起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) // 扇区11起始地址, 128 Kbytes
/* Exported constants --------------------------------------------------------*/

/* Exported macro ------------------------------------------------------------*/

/* Exported functions ------------------------------------------------------- */
void bsp_flash_unlock(void);
void bsp_flash_lock(void);

uint8_t bsp_flash_erase_sector(uint32_t sector_addr);
int bsp_flash_write(uint32_t addr, uint32_t data);
int bsp_flash_write_words(uint32_t addr, uint32_t *data,uint16_t size);

uint8_t bsp_flash_erase(uint32_t addr, uint32_t size);
#endif /* BSP_FLASH_H */
